package org.mimizet;

/**
 * User: Admin
 * Date: 29.08.11
 * Time: 0:30
 */
public class MethodCall {
    public String className;
    public String methodName;

    public Object[] parameters;
    public Object result;
    
    /**
     * Means following data flow: load from storage -> convert array to iterator OR convert iterator to array -> save to storage 
     */
    public String resultConverterClass;

    protected MethodCall(String className, String methodName, Object[] parameters) {
        this.className = className;
        this.methodName = methodName;
        this.parameters = parameters;
    }

    protected MethodCall(String className, String methodName, Object[] parameters, Object result) {
        this.className = className;
        this.methodName = methodName;
        this.parameters = parameters;
        this.result = result;
    }

    public String toString(){
        StringBuilder append = new StringBuilder(1024)
                .append(methodName)
                .append("_(");

        for (int i = 0; i < parameters.length; i++) {
            Object parameter = parameters[i];
            append.append(parameter.toString());
            if(i != parameters.length - 1){
                append.append(", ");
            }
        }

        append.append(")");

        return append.toString();
    }

	public ConversionResult packResult(Converter converter) {
        ConversionResult conversionResult = converter.from(result);
        result = conversionResult.result;
        return conversionResult;
	}
	
	public void unpackResult(Converter converter) {
		result = converter.to(result);
	}


}
